﻿@model DataAccess.DB.ThanhToan

@{
    ViewBag.Title = "Thanh toán";
}

<style>
    #Date {
        width: 120px;
    }

    #Price {
        width: 180px;
        text-align: right;
    }
</style>
<script src="~/Scripts/CustomValidate.js" type="text/javascript"></script>

@using (Html.BeginForm())
{
    @Html.ValidationSummary(true)

    <fieldset>
        <legend>Thanh toán cho ĐVCC</legend>
        <table>
            <tr>
                <td class="editor-label">Đơn vị cung cấp:
                </td>
                <td class="editor-field">
                    @Html.HiddenFor(model => model.ID_DVCC) @Html.TextBox("txtSearch")
                    <input id="popupKhachHang" type="button" value="+" style="width: 30px" />
                    @Html.ValidationMessageFor(model => model.ID_DVCC)
                </td>
            </tr>
            <tr>
                <td>
                    <span>Tên DVCC</span>
                </td>
                <td>
                    @Html.TextBox("txtTenKH")
                </td>
            </tr>
            <tr>
                <td>
                    <span>Địa chỉ</span>
                </td>
                <td>
                    @Html.TextBox("txtDiaChi")
                </td>
            </tr>
            <tr>
                <td class="editor-label">Tiền thanh toán:
                </td>
                <td class="editor-field">
                    @Html.EditorFor(model => model.Price)
                    @Html.ValidationMessageFor(model => model.Price)
                </td>
            </tr>
            <tr>
                <td class="editor-label">Ngày trả tiền:
                </td>
                <td class="editor-field">
                    @Html.EditorFor(model => model.Date)
                    @Html.ValidationMessageFor(model => model.Date)
                </td>
            </tr>

        </table>
        <p>
            <input type="submit" value="Lưu" class="btnCreate" />@Html.ActionLink("Thoát", "Index", null, new { @class = "linkCreate" })
        </p>
    </fieldset>
    
}
<div id="dialog-KH" style="display: none" title="Danh sách khách hàng">
</div>

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
    <script type="text/javascript">
        
        $("#Price").change(function () {
            $("#Price").formatCurrency();
        });
        $("#popupKhachHang").click(function () {
            $("#dialog-KH").dialog({
                width: 1000,
                height: 600,
                modal: true,

                open: function () {
                    $(this).load("/DVCC/IndexPopup", function () {
                        $("#txtMaKH").focus();
                        $(document).on('input', '#txtMaKH', function () {
                            var valueSearch = $(this).val();
                            $.ajax({
                                url: '@Url.Action("GetTableDVCCById", "DVCC")',
                                type: 'POST',
                                data: { "valueSearch": valueSearch },
                                dataType: 'json',
                                success: function (response) {
                                    var productDetails = response.ProductDetail;
                                    $("#tablekh tbody").html(productDetails);
                                }
                            });

                        });
                        $(".btnChon").click(function () {
                            var idKH = $(this).attr('id');

                            $.ajax({
                                url: '@Url.Action("GetDVCCsById", "DVCC")',
                                type: 'POST',
                                data: { "valueSearch": idKH },
                                dataType: 'json',
                                success: function (response) {
                                    var KhachHangDetail = response.KhachHangDetail;
                                    var listKhachHangInfo = KhachHangDetail.split(";#");
                                    $("#txtSearch").val(listKhachHangInfo[1]);
                                    $("#txtTenKH").val(listKhachHangInfo[2]);
                                    $("#txtDiaChi").val(listKhachHangInfo[3]);
                                    $("#ID_DVCC").val(listKhachHangInfo[0])
                                    $("#dialog-KH").dialog("close");
                                }
                            });
                        });
                    });

                },

            });
            $("#dialog-KH").dialog("open");
        });

        function SelectKH(idKH) {

            $.ajax({
                url: '@Url.Action("GetDVCCsById", "DVCC")',
                type: 'POST',
                data: { "valueSearch": idKH },
                dataType: 'json',
                success: function (response) {
                    var KhachHangDetail = response.KhachHangDetail;
                    var listKhachHangInfo = KhachHangDetail.split(";#");
                    $("#txtSearch").val(listKhachHangInfo[1]);
                    $("#txtTenKH").val(listKhachHangInfo[2]);
                    $("#txtDiaChi").val(listKhachHangInfo[3]);
                    $("#ID_DVCC").val(listKhachHangInfo[0])
                    $("#dialog-KH").dialog("close");
                }
            });
        }

        $(':input').mouseover(function () {
            $(this).attr("title", $(this).val());
        });
    </script>
}
